package com.jianguo.quartz.task;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.jianguo.order.domain.PzOrder;
import com.jianguo.order.service.IPzOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 订单定时
 */
@Component("orderTask")
public class OrderTask {
    @Autowired
    private IPzOrderService orderService;
    /**
     * 删除过期没人接的订单
     */
    public void removeOrder()
    {
        // 24小时前的时间
        LocalDateTime time = LocalDateTime.now().minusHours(24L);
        // 状态为待接单，超时24小时
        LambdaUpdateWrapper<PzOrder> updateWrapper = new LambdaUpdateWrapper<PzOrder>().set(PzOrder::getStatus, 5)
                .eq(PzOrder::getStatus, 0).lt(PzOrder::getPaytime, time);
        orderService.update(updateWrapper);
    }
}
